package org.ponly.cta4j.service;

import org.ponly.cta4j.CaptchaFactory;
import org.ponly.cta4j.factory.gimpy.DefaultFactory;
import org.ponly.cta4j.service.store.CaptchaStore;

/**
 * 默认验证码服务.
 *
 * @author vacoor
 */
public class DefaultManageableCaptchaService extends AbstractManageableCaptchaService {

    public DefaultManageableCaptchaService(final CaptchaStore store) {
        this(store, DefaultFactory.INSTANCE, 180, 100000, 75000);
    }

    public DefaultManageableCaptchaService(final CaptchaStore store, final CaptchaFactory factory) {
        this(store, factory, 180, 100000, 75000);
    }

    public DefaultManageableCaptchaService(final CaptchaStore store, final CaptchaFactory factory,
                                           final int minGuarantedStorageDelayInSeconds, final int captchaStoreMaxSize) {
        this(store, factory, minGuarantedStorageDelayInSeconds, captchaStoreMaxSize, (int) Math.round(captchaStoreMaxSize * 0.75));
    }

    /**
     * 使用给定配置构建一个验证码服务.
     *
     * @param captchaStore                            验证码存储
     * @param captchaFactory                          验证码工厂
     * @param minGuarantedStorageDelayInSeconds       验证码最小有效期
     * @param captchaStoreMaxSize                     验证码最大容量
     * @param captchaStoreSizeBeforeGarbageCollection 触发垃圾回收的阈值
     */
    public DefaultManageableCaptchaService(final CaptchaStore captchaStore,
                                           final CaptchaFactory captchaFactory,
                                           final int minGuarantedStorageDelayInSeconds,
                                           final int captchaStoreMaxSize,
                                           final int captchaStoreSizeBeforeGarbageCollection) {
        super(captchaStore, captchaFactory, minGuarantedStorageDelayInSeconds, captchaStoreMaxSize, captchaStoreSizeBeforeGarbageCollection);
    }
}
